#!/user/bin/env node

const fs = require('fs'),
      sfile = process.argv[2],
      dfile = process.argv[3];
try{
const sfid = fs.openSync(sfile,'r'),
      dfid = fs.openSync(dfile,'w');

fs.writeFileSync(dfid,fs.readFileSync(sfid).toString('utf8'));

fs.closeSync(sfid);
fs.closeSync(dfid);
}catch(e){
  console.error(e.message);
  process.exit(1);
}

let stm = fs.createReadStream(sfile).pipe(fs.createWriteStream(dfile));

stm.on('close',()=>{
  fs.chmodSync(dfile,fs.statSync(sfile).mode);
})
